<include file="Public/header" />
<include file="Public/menu" />
<link rel="stylesheet" href="/Public/admin/adminlte/bootstrap/css/bootstrap-switch.min.css">

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            广告
            <small>管理</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="{:U('Special/advert')}"><i class="fa fa-dashboard"></i> 专题</a></li>
            <li class="active">广告</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content">

        <div class="row"><div class="col-md-12"><div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <!--<li class="<?php echo empty($_GET['type']) ? 'active': '';?>"><a href="/Qgs/DiscountCoupon/index">进行中</a></li>-->
                <!--<li class="<?php echo $_GET['type'] == 'timeout' ? 'active': '';?>"><a href="/Qgs/DiscountCoupon/index/type/timeout">已到期</a></li>-->


                <li class="pull-right header"></li>
            </ul>
            <div class="tab-content">
                <div class="box-header">
                    <h3 class="box-title"></h3>
                    <div class="btn-group pull-left" style="margin-right: 10px">
                        <a href="{:U('Special/advertAdd')}" class="btn btn-sm btn-success" style="height:30px"><i class="fa fa-save"></i>&nbsp;&nbsp;添加广告</a>
                    </div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <p class="btn-group pull-left" style="margin-right: 10px">
                       <p class="btn  btn-default" >每个店铺随机推送 <input type="text" class="num"  size="1" style="height:20px" value="1">个广告</p><button class="btn btn-sm btn-info push" style="height:35px"><i class="glyphicon glyphicon-fire"></i>&nbsp;&nbsp;推送</button>
                    </div>

                    <!--<div class="form-inline pull-right">
                        <form action="/Qgs/purchase/shoppingList/view/0/order_field/last_modify/order/asc" method="get" pjax-container="">
                            <fieldset>
                                <div class="input-group input-group-sm">
                                    <span class="input-group-addon"><strong>名称</strong></span>
                                    <input type="hidden" name="search_field" value="local_name">
                                    <input type="text" class="form-control" placeholder="搜索" name="search" value="">
                                </div>
                                <div class="input-group input-group-sm">
                                    <div class="input-group-btn">
                                        <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>-->
                </div>

                <div class="tab-pane active" id="tab_0">
                    <div class="box">

                        <!-- /.box-header -->
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover" style="width: 100%;">
                                <tbody><tr>
                                    <th></th>
                                    <th>广告标题</th>
                                    <th>链接地址</th>
                                    <th>图片</th>
                                    <th>优先级</th>
                                    <th>状态</th>
                                    <!--<th>开始时间</th>-->
                                    <th>添加时间</th>
                                    <th>操作</th>
                                </tr>
                                <foreach name="rows" item="v">
                                    <tr>
                                        <td></td>
                                        <td class="tit">{$v.name}</td>
                                        <td><a href="{$v.url}" >{$v.url}</a></td>
                                        <td><img src="/Uploads/{$v.image}" class="img" width="50" height="30"/></td>
                                        <td>{$v.order}</td>
                                        <td> <div class="switch">
                                            <input type="checkbox" name="status" data-size="mini" data-id="{$v.id}" data-on-text="显示" data-off-text="不显示" <if condition="$v['status'] eq 1 ">checked</if>>
                                        </div>





                                        </td>

                                        <!--<td>{:date("Y-m-d H:i:s",$v['start_time'])}</td>-->
                                        <td>{:date("Y-m-d H:i:s",$v['create_time'])}</td>
                                        <td>
                                            <?php if (empty($_GET['type'])){ ?>
                                            <a href="{:U('advertedit',array('id'=>$v['id']))}" class="btn btn-sm btn-primary">修改</a>
                                            <?php } ?>
                                            <a href="javascript:void(0);" delid="{$v['id']}" title="删除" class="delete btn btn-sm btn-danger grid-refreshe"  >删除</a>
                                        </td>
                                    </tr>
                                </foreach>
                                </tbody>
                            </table>
                        </div>
                        <div class="box-footer clearfix">
                            <!--<input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;-->
                            <!--<a class="btn btn-sm btn-danger batch-delete">批量删除</a>-->

                            <!--<a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>-->

                            <ul class="pagination pagination-sm no-margin pull-right">    </ul>
                            {$show}
                        </div>
                        <!-- /.box-body -->
                    </div>

                </div>

                <div class="tab-pane " id="tab_">
                    <div class="box">
                        <div class="box-body table-responsive no-padding">
                        </div>
                    </div>
                </div>


            </div>
        </div></div></div>

    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer" />
<script src="__PUBLIC__/admin/adminlte/bootstrap/js/bootstrap-switch.min.js"></script>
<script src="/Public/layer/layer.js"></script>
<script>
    $('.exchange-code').click(function () {
        var href = $(this).attr('href-data');
        layer.ready(function(){
            layer.open({
                type: 2,
                title: '添加广告',
                fix: false,
                maxmin: true,
                shadeClose: true,
                area: ['1100px', '800px'],
                content: href,
                end: function(){
                    layer.tips('Hi', '#about', {tips: 1})
                }
            });
        });
    });

    $(function(){
        $(".delete").click(function(){
            var id = $(this).attr('delid');

            layer.confirm('确认删除吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                // 获取id
                $.post("{:U('advertdelete')}",{'id':id},function(data){
                    if (data.status) {
                        layer.msg(data.message, {icon: 1});
                        setTimeout(function(){
                            history.go(0)
                        },2000)
                    }else{
                        layer.msg(data.message, {icon: 2});
                    }
                },'json');

            });
        });

        //推送广告
        $('.push').click(function(){
              var num = $('.num').val();
            $.getJSON('{:U("advertPush")}',{num:num},function(data){
                if (data.status) {
                    layer.msg(data.message, {icon: 1});
                }else{
                    layer.msg(data.message, {icon: 2});
                }
            });



        });



        // 查看大图

        $('.img').mousemove(function(){
            var img =$(this).attr('src');
            var title =$('.tit').text();
            layer.open({
                type: 1,
                title: title,
                closeBtn: 2,
                area: '750px',
                skin: 'layui-layer-nobg', //没有背景色
                shadeClose: true,
                content: '<img src="'+img+'" width="750" height="185" />'
            });
        })


    })

    $(function(argument) {
        $('.grid-select-all').change(function () {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        $('.switch [type="checkbox"]').bootstrapSwitch();

        $('input[name="status"]').on('switchChange.bootstrapSwitch', function (event, status) {
            var id = $(this).attr('data-id');
            $.ajax({
                type: 'get',
                url: "{:U('change')}",
                data: {id: id, status: status},
                success: function (msg) {

                },
                error: function (msg) {
                    alert(msg.message);
                }
            })
        });


    })
</script>

